Programming Questions for Practice
A company is transmitting data to another server. The data is in the form of numbers. To secure the data during transmission, they plan to obtain a security key that will be sent along with the data. The security key is identified as the count of the unique repeating digits in the data.
Write an algorithm to find the security key for the data.
#include <stdio.h>
#include <stdlib.h>
int securityKey(int data) {
int answer = 0, digit, i;
int allDigits[10] = {0};
while(data != 0) {
digit = data % 10;
allDigits[digit]++;
data = data / 10;
}
for(i = 0; i < 10; i++) {
if(allDigits[i] > 1)
answer++;
}
return answer;
}
int main()
{
int number;
printf("Enter any integer: ");
scanf("%d", &number);
printf("Result = %d\n", securityKey(number));
return 0;
}
Code not available...
Code not available...